package com.pwser.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.pwser.entity.User;
import com.pwser.service.UserService;

@RestController
public class RedisController {
	@Autowired
	private UserService userService;
	
	@GetMapping("/get/{id}")
	public User getUser(@PathVariable int id) {
		return userService.getUserById(id);
	}
	
	@GetMapping("/add")
	public String addUser() {
		User user = new User();
		user.setUserId(9999);
		user.setUserName("abc");
		userService.addUser(user);
		return "success";
	}
	
	@GetMapping("/edit")
	public String editUser() {
		User user = new User();
		user.setUserId(7777);
		user.setUserName("更新后的姓名值");
		userService.editUser(user);
		return "success";
	}
	
	@GetMapping("/delete/{id}")
	public String delete(@PathVariable int id) {
		userService.delUser(id);
		return "success";
	}
	
	@GetMapping("/get2/{id}")
	public User getUser2(@PathVariable int id) {
		return userService.getUserByIdToRedis(id);
	}
	
	@GetMapping("/getAll")
	public List<User> getAll() {
		return userService.getAllUsers();
	}
	
	@GetMapping("/getCon/{id}")
	public List<User> getCon(@PathVariable int id) {
		User user = new User();
		user.setUserId(id);
		return userService.getUsersByCondition(user);
	}
	
}
